home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" ?>
-
- <bindings id="tabscopeBindings"
- xmlns="http://www.mozilla.org/xbl"
- xmlns:xbl="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:html="http://www.w3.org/1999/xhtml">
-
- <binding id="tabscope-popup" extends="chrome://global/content/bindings/popup.xml#popup">
-
- <resources>
- <stylesheet src="chrome://tabscope/skin/tabscope.css" />
- </resources>
-
- <content ignorekeys="true" noautofocus="true">
- <xul:label anonid="tabscope-label" class="tabscope-label" crop="end" />
- <xul:hbox anonid="tabscope-toolbar">
- <xul:toolbarbutton anonid="tabscope-back" class="tabscope-back" />
- <xul:toolbarbutton anonid="tabscope-forward" class="tabscope-forward" />
- <xul:toolbarbutton anonid="tabscope-reload" class="tabscope-reload" />
- <xul:toolbarbutton anonid="tabscope-stop" class="tabscope-stop" />
- <xul:toolbarbutton anonid="tabscope-zoom" class="tabscope-zoom" />
- <xul:toolbarbutton anonid="tabscope-close" class="tabscope-close" />
- </xul:hbox>
- <xul:hbox anonid="tabscope-canvas-box" class="tabscope-canvas-box">
- <html:canvas anonid="tabscope-canvas" class="tabscope-canvas" />
- </xul:hbox>
- </content>
-
- <implementation implements="nsIDOMEventListener,nsITimerCallback">
-
- <!-- xul:tabbrowser -->
- <field name="_tabbrowser">null</field>
-
- <!-- xul:tab -->
- <field name="_tab">null</field>
-
- <!-- xul:browser -->
- <field name="_browser">null</field>
-
- <!-- timer id to show popup -->
- <field name="_showTimerID">null</field>
-
- <!-- nsITimer to refresh popup -->
- <field name="_refreshTimer">null</field>
-
- <!-- last time when hiding popup -->
- <field name="_lastTimeToHide">0</field>
-
- <!-- cache of prefs -->
- <field name="_prefs">null</field>
-
- <!-- quick access to canvas -->
- <field name="canvas">null</field>
-
- <!-- mode of preview scale -->
- <field name="_scaleMode">1</field>
-
- <!-- nsIWebProgressListener -->
- <field name="_progressListener"><![CDATA[
- ({
- _shouldRefresh: false,
- onLocationChange: function() { this._shouldRefresh = true; },
- onProgressChange: function() { this._shouldRefresh = true; },
- onSecurityChange: function() { this._shouldRefresh = true; },
- onStateChange : function() { this._shouldRefresh = true; },
- onStatusChange : function() { this._shouldRefresh = true; },
- QueryInterface: function(aIID) {
- const Ci = Components.interfaces;
- if (aIID.equals(Ci.nsIWebProgressListener) ||
- aIID.equals(Ci.nsISupportsWeakReference) ||
- aIID.equals(Ci.nsISupports))
- return this;
- throw Components.results.NS_NOINTERFACE;
- }
- })
- ]]></field>
-
- <method name="log">
- <parameter name="aMessage" />
- <parameter name="aAddTime" />
- <body><![CDATA[
- dump("tabscope" + (aAddTime ? "@" + new Date().toLocaleTimeString() : "") + "> " + aMessage + "\n");
- ]]></body>
- </method>
-
- <method name="getElement">
- <parameter name="aAnonymousID"/>
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", aAnonymousID)
- ]]></body>
- </method>
-
- <method name="abort">
- <body><![CDATA[
- if (this._showTimerID) {
- window.clearTimeout(this._showTimerID);
- this._showTimerID = null;
- }
- if (this._tab)
- this.hidePopup();
- this._tab = null;
- ]]></body>
- </method>
-
- <method name="refresh">
- <body><![CDATA[
- this.getElement("tabscope-back").disabled = !this._browser.canGoBack;
- this.getElement("tabscope-forward").disabled = !this._browser.canGoForward;
- this.getElement("tabscope-stop").disabled = !this._browser.webProgress.isLoadingDocument;
- this.getElement("tabscope-label").value = this._tab.label;
- this.getElement("tabscope-label").setAttribute("tooltiptext", this._tab.label);
- var win = this._browser.contentWindow;
- var empty = win.location.href == "about:blank";
- var showTitle = empty || this._prefs["show_title"];
- this.getElement("tabscope-label").style.display = showTitle ? "block" : "none";
- this.getElement("tabscope-toolbar").style.display = empty ? "none" : "block";
- this.getElement("tabscope-canvas-box").style.display = empty ? "none" : "block";
- this.getElement("tabscope-label").width = empty ? null : this.canvas.width;
- if (empty)
- return;
- var w, h;
- var s = this.canvas.scale || this._prefs["preview_scale"];
- if (s == 0) {
- w = win.innerWidth;
- s = this.canvas.width / w;
- h = this.canvas.height / s;
- }
- else {
- w = this.canvas.width / s;
- h = this.canvas.height / s;
- }
- var ctx = this.canvas.getContext("2d");
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
- ctx.save();
- ctx.scale(s, s);
- ctx.drawWindow(win, win.scrollX, win.scrollY, w, h, "rgb(255,255,255)");
- ctx.restore();
- ]]></body>
- </method>
-
- <method name="toggleScale">
- <body><![CDATA[
- if (this._scaleMode == 1) {
- this._scaleMode = 2;
- this.canvas.width = this._prefs["preview_width.2"];
- this.canvas.height = this._prefs["preview_height.2"];
- this.canvas.scale = this._prefs["preview_scale.2"];
- }
- else {
- this._scaleMode = 1;
- this._initCanvasWithPrefs();
- }
- this.refresh();
- ]]></body>
- </method>
-
- <method name="_handleMouseOver">
- <parameter name="aEvent" />
- <body><![CDATA[
- if (this._showTimerID || this._refreshTimer)
- return;
- var allTabs = false;
- if (aEvent.target.localName == "tab") {
- if (aEvent.target == this._tab)
- return;
- if (!this._prefs["current_tab"] && aEvent.target == this._tabbrowser.mCurrentTab) {
- this.abort();
- return;
- }
- }
- else if (aEvent.originalTarget.localName == "menuitem" && aEvent.originalTarget.tab) {
- allTabs = true;
- }
- else {
- return;
- }
- this._tab = !allTabs ? aEvent.target : aEvent.originalTarget.tab;
- var anchor = !allTabs ? aEvent.target : aEvent.originalTarget;
- var callback = function(self) {
- var position = "";
- if (!allTabs) {
- switch (self._prefs["popup_alignment"]) {
- case 1: position = "before_start"; break;
- case 2: position = "after_start"; break;
- case 3: position = "start_before"; break;
- case 4: position = "end_before"; break;
- }
- }
- else
- position = (self._prefs["popup_alignment"] == 1) ? "end_after" : "end_before";
- self.openPopup(anchor, position, 0, 0, true, false);
- };
- var delay = this._prefs["continuously"] && (Date.now() - this._lastTimeToHide <= 50)
- ? 10 : this._prefs["popup_delay"];
- this._showTimerID = window.setTimeout(callback, delay, this);
- ]]></body>
- </method>
-
- <method name="_handleMouseOut">
- <parameter name="aEvent" />
- <body><![CDATA[
- var rel = aEvent.relatedTarget;
- if (rel) {
- while (rel) {
- if (rel == this._tab || rel == this)
- return;
- rel = rel.parentNode;
- }
- this.abort();
- return;
- }
- var x = aEvent.screenX;
- var y = aEvent.screenY;
- if (this._refreshTimer) {
- if (this._isEntering(x, y, this, false) ||
- this._isEntering(x, y, this._tab, true))
- return;
- }
- this.abort();
- ]]></body>
- </method>
-
- <method name="_isEntering">
- <parameter name="aScreenX" />
- <parameter name="aScreenY" />
- <parameter name="aElement" />
- <parameter name="aAllowOnEdge" />
- <body><![CDATA[
- var x = aElement.boxObject.screenX;
- var y = aElement.boxObject.screenY;
- var c = aAllowOnEdge ? 1 : 0;
- if (x < aScreenX - c && aScreenX < x + aElement.boxObject.width + c &&
- y < aScreenY - c && aScreenY < y + aElement.boxObject.height + c) {
- return true;
- }
- return false;
- ]]></body>
- </method>
-
- <method name="readPrefs">
- <body><![CDATA[
- var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService);
- prefBranch = prefBranch.getBranch("extensions.tabscope.");
- this._prefs = {
- "popup_alignment" : prefBranch.getIntPref("popup_alignment"),
- "popup_delay" : prefBranch.getIntPref("popup_delay"),
- "continuously" : prefBranch.getBoolPref("continuously"),
- "current_tab" : prefBranch.getBoolPref("current_tab"),
- "show_title" : prefBranch.getBoolPref("show_title"),
- "preview_width" : prefBranch.getIntPref("preview_width"),
- "preview_height" : prefBranch.getIntPref("preview_height"),
- "preview_scale" : prefBranch.getIntPref("preview_scale") / 100,
- "preview_width.2" : prefBranch.getIntPref("preview_width.2"),
- "preview_height.2" : prefBranch.getIntPref("preview_height.2"),
- "preview_scale.2" : prefBranch.getIntPref("preview_scale.2") / 100,
- };
- this._initCanvasWithPrefs();
- this.style.MozBoxDirection = (this._prefs["popup_alignment"] == 1) ? "reverse" : "";
- ]]></body>
- </method>
-
- <method name="_initCanvasWithPrefs">
- <body><![CDATA[
- this.canvas.width = this._prefs["preview_width"];
- this.canvas.height = this._prefs["preview_height"];
- this.canvas.scale = this._prefs["preview_scale"];
- ]]></body>
- </method>
-
- <method name="_getActualElementAndPoint">
- <parameter name="aScreenX" />
- <parameter name="aScreenY" />
- <body><![CDATA[
- var win = this._browser.contentWindow;
- var box = document.getBoxObjectFor(this.canvas);
- var x = aScreenX - box.screenX;
- var y = aScreenY - box.screenY;
- var css = window.getComputedStyle(this.canvas, null);
- x -= parseInt(css.marginLeft, 10) + parseInt(css.borderLeftWidth, 10) + parseInt(css.paddingLeft, 10);
- y -= parseInt(css.marginTop, 10) + parseInt(css.borderTopWidth, 10) + parseInt(css.paddingTop, 10);
- var scale = this.canvas.scale || this.canvas.width / win.innerWidth;
- x = Math.round(x / scale);
- y = Math.round(y / scale);
- var elt = win.document.elementFromPoint(x, y);
- var nest = 0;
- while (elt.localName.toLowerCase() == "iframe" || elt.localName.toLowerCase() == "frame") {
- if (++nest > 10)
- break;
- x -= elt.getBoundingClientRect().left;
- y -= elt.getBoundingClientRect().top;
- elt = elt.contentDocument.elementFromPoint(x, y);
- }
- return [elt, x, y];
- ]]></body>
- </method>
-
- <constructor><![CDATA[
- this.canvas = this.getElement("tabscope-canvas");
- this.readPrefs();
- this._tabbrowser = document.getElementById(this.getAttribute("browserid"));
- this._tabbrowser.mStrip.tooltip = null;
- this._tabbrowser.mStrip.addEventListener("mouseover", this, false);
- this._tabbrowser.mStrip.addEventListener("mouseout", this, false);
- this._tabbrowser.mStrip.addEventListener("click", this, false);
- setTimeout(function(self){
- self._tabbrowser.mTabContainer.addEventListener("TabSelect", self, false);
- self._tabbrowser.mTabContainer.addEventListener("TabClose", self, false);
- }, 100, this);
- ]]></constructor>
-
- <destructor><![CDATA[
- this.canvas = null;
- this._tabbrowser = null;
- ]]></destructor>
-
- <!-- nsIDOMEventListener -->
- <method name="handleEvent">
- <parameter name="aEvent" />
- <body><![CDATA[
- switch (aEvent.type) {
- case "mouseover":
- this._handleMouseOver(aEvent);
- break;
- case "mouseout":
- this._handleMouseOut(aEvent);
- break;
- default:
- this.abort();
- break;
- }
- ]]></body>
- </method>
-
- <!-- nsITimerCallback -->
- <method name="notify">
- <parameter name="aTimer" />
- <body><![CDATA[
- if (this._progressListener._shouldRefresh) {
- this._progressListener._shouldRefresh = false;
- this.refresh();
- }
- ]]></body>
- </method>
-
- </implementation>
-
- <handlers>
-
- <handler event="popupshowing" phase="capturing"><![CDATA[
- if (this._refreshTimer) {
- this._refreshTimer.cancel();
- this._refreshTimer = null;
- }
- this._refreshTimer = Components.classes["@mozilla.org/timer;1"]
- .createInstance(Components.interfaces.nsITimer);
- this._refreshTimer.initWithCallback(this, 500, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
- this._browser = this._tabbrowser.getBrowserForTab(this._tab);
- this._browser.addProgressListener(this._progressListener);
- this.refresh();
- ]]></handler>
-
- <handler event="popuphiding" phase="capturing"><![CDATA[
- this._lastTimeToHide = Date.now();
- this._refreshTimer.cancel();
- this._refreshTimer = null;
- this._browser.removeProgressListener(this._progressListener);
- this._browser = null;
- this._tab = null;
- if (gContextMenu)
- gContextMenu.menu.hidePopup();
- var tabMenu = document.getAnonymousElementByAttribute(this._tabbrowser, "anonid", "tabContextMenu");
- tabMenu.hidePopup();
- ]]></handler>
-
- <handler event="mouseout" phase="capturing"><![CDATA[
- this._handleMouseOut(event);
- ]]></handler>
-
- <handler event="command"><![CDATA[
- switch (event.originalTarget.getAttribute("anonid")) {
- case "tabscope-back" : this._browser.goBack(); break;
- case "tabscope-forward": this._browser.goForward(); break;
- case "tabscope-reload" : this._browser.reload(); break;
- case "tabscope-stop" : this._browser.stop(); break;
- case "tabscope-zoom" : this.toggleScale(); break;
- case "tabscope-close" :
- this._tabbrowser.removeTab(this._tab);
- this.abort();
- var popup = this._tabbrowser.mTabContainer.mAllTabsPopup;
- if (popup && popup.hasChildNodes())
- popup.hidePopup();
- break;
- default:
- }
- ]]></handler>
-
- <handler event="click" button="0"><![CDATA[
- var targetName = event.originalTarget.localName;
- if (targetName == "label" || targetName == "popup") {
- this._tabbrowser.selectedTab = this._tab;
- this.abort();
- }
- else if (targetName == "canvas") {
- var [elt, x, y] = this._getActualElementAndPoint(event.screenX, event.screenY);
- if (!elt)
- return;
- var evt = elt.ownerDocument.createEvent("MouseEvents");
- evt.initMouseEvent(
- event.type, true, false, elt.ownerDocument.defaultView, event.detail,
- event.screenX, event.screenY, x, y,
- event.ctrlKey, event.altKey, event.shiftKey, event.metaKey,
- event.button, null
- );
- elt.dispatchEvent(evt);
- this.refresh();
- }
- ]]></handler>
-
- <handler event="click" button="1"><![CDATA[
- this.abort();
- ]]></handler>
-
- <handler event="click" button="2"><![CDATA[
- if (this.getElement("tabscope-canvas-box").style.display == "none")
- return;
- this.toggleScale();
- ]]></handler>
-
- <handler event="DOMMouseScroll" phase="capturing"><![CDATA[
- var [elt, , ] = this._getActualElementAndPoint(event.screenX, event.screenY);
- if (!elt)
- return;
- elt.ownerDocument.defaultView.scrollBy(0, event.detail < 0 ? -100 : 100);
- this.refresh();
- ]]></handler>
-
- </handlers>
-
- </binding>
-
- </bindings>
-